require('./bootstrap');

window.showMenu = () => {
    const menu = $('#menu')
    if (menu.css('display') === 'none') {
        menu.show();
    } else {
        menu.hide()
    }
}

window.justifiedLayout = require('justified-layout')

window.copy = (content) => {
    var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if(isAndroid || (!isAndroid && !isiOS)){
        const txt = document.createElement('textarea');
        txt.style = 'position:absolute;top:-9999px;left:-9999px;';
        txt.setAttribute('id',"selector");
        txt.setAttribute('readonly','readonly');
        txt.innerHTML = content;
        $('body').append(txt);
        $("#selector").select();
        document.execCommand("copy",false,null);
    }
    if(isiOS){
        const txt = document.createElement('a');
        txt.setAttribute('id',"selector");
        txt.setAttribute('style','position:absolute;top:-9999px;left:-9999px;');
        txt.innerHTML = content;
        $('body').append(txt);
        var copyDOM = document.querySelectorAll('#selector');
        var range = document.createRange();
        range.selectNode(copyDOM[0]);
        window.getSelection().removeAllRanges();
        window.getSelection().addRange(range);
        document.execCommand('copy');
    }
    $("#selector").remove();
}
